package com.ruoyi.homework.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.homework.domain.TechHomework;
import com.ruoyi.homework.service.ITechHomeworkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作业Controller
 * 
 * @author admin
 * @date 2022-08-06
 */
@RestController
@RequestMapping("/homework/homework")
public class TechHomeworkController extends BaseController
{
    @Autowired
    private ITechHomeworkService techHomeworkService;

    /**
     * 查询作业列表
     */
    @PreAuthorize("@ss.hasPermi('homework:homework:list')")
    @GetMapping("/list")
    public TableDataInfo list(TechHomework techHomework)
    {
        startPage();
        List<TechHomework> list = techHomeworkService.selectTechHomeworkList(techHomework);
        return getDataTable(list);
    }

    /**
     * 导出作业列表
     */
    @PreAuthorize("@ss.hasPermi('homework:homework:export')")
    @Log(title = "作业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TechHomework techHomework)
    {
        List<TechHomework> list = techHomeworkService.selectTechHomeworkList(techHomework);
        ExcelUtil<TechHomework> util = new ExcelUtil<TechHomework>(TechHomework.class);
        util.exportExcel(response, list, "作业数据");
    }

    /**
     * 获取作业详细信息
     */
    @PreAuthorize("@ss.hasPermi('homework:homework:query')")
    @GetMapping(value = "/{hwId}")
    public AjaxResult getInfo(@PathVariable("hwId") Long hwId)
    {
        return AjaxResult.success(techHomeworkService.selectTechHomeworkByHwId(hwId));
    }

    /**
     * 新增作业
     */
    @PreAuthorize("@ss.hasPermi('homework:homework:add')")
    @Log(title = "作业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechHomework techHomework)
    {
        return toAjax(techHomeworkService.insertTechHomework(techHomework));
    }

    /**
     * 修改作业
     */
    @PreAuthorize("@ss.hasPermi('homework:homework:edit')")
    @Log(title = "作业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechHomework techHomework)
    {
        return toAjax(techHomeworkService.updateTechHomework(techHomework));
    }

    /**
     * 删除作业
     */
    @PreAuthorize("@ss.hasPermi('homework:homework:remove')")
    @Log(title = "作业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hwIds}")
    public AjaxResult remove(@PathVariable Long[] hwIds)
    {
        return toAjax(techHomeworkService.deleteTechHomeworkByHwIds(hwIds));
    }
}
